package com.xiaomai.eduorder.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaomai.commonutil.JwtUtils;
import com.xiaomai.commonutil.R;
import com.xiaomai.eduorder.entity.Order;
import com.xiaomai.eduorder.service.OrderService;
import com.xiaomai.eduorder.service.PayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-10-17
 */
@RestController

@RequestMapping("/eduorder/order")

public class OrderController {

    @Autowired
    private OrderService orderService;

    //1.创建订单
    @PostMapping("createOrder/{courseId}")
    public R saveOrder(@PathVariable String courseId,
                       HttpServletRequest request){

        //创建订单
     String orderNo = orderService.createOrders(courseId, JwtUtils.getMemberIdByJwtToken(request));//1.通过courseId获取课程信息
    //将存进的订单号返回                                                                                                // 2.通过request获取用户信息
    return R.ok().data("orderId",orderNo);
    }
    //2.获取订单信息生成订单
    @GetMapping("getOrderInfo/{orderId}")
    public R getOrderInfo(@PathVariable String orderId){
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        //设置字段名order_no是orderId的条件
        wrapper.eq("order_no",orderId);
        //根据条件获取到对象
        Order order = orderService.getOne(wrapper);
//        将该对象返回
        return R.ok().data("order",order);
    }



}

